I have files stored in a database that I need a Web API to return. The database call correctly returns the proper byte array (Breakpoint shows the array being around 67000 in length, which is correct), but when I make a call to the Web API, I never get that content in the response. I've tried using a MemoryStream and ByteArrayContent, and neither give me the results I should be getting. I've tried calling from both Postman and my MVC application, but neither return the byte array, just the basic response information with headers/success/etc.

public HttpResponseMessage GetFile(int id)
{
    var fileToDownload = getFileFromDatabase(id);
    if (fileToDownload == null)
    {
        return new HttpResponseMessage(HttpStatusCode.BadRequest);
    }
    var response = new HttpResponseMessage(HttpStatusCode.OK);
    response.Content = new ByteArrayContent(fileToDownload.FileData); //FileData is just a byte[] property in this class
    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
    return response;
}

Typical Response I get (with no byte content anywhere to be found):

{
  "version": {
    "major": 1,
    "minor": 1,
    "build": -1,
    "revision": -1,
    "majorRevision": -1,
    "minorRevision": -1
  },
  "content": {
    "headers": [
      {
        "key": "Content-Disposition",
        "value": [
          "attachment"
        ]
      },
      {
        "key": "Content-Type",
        "value": [
          "application/octet-stream"
        ]
      }
    ]
  },
  "statusCode": 200,
  "reasonPhrase": "OK",
  "headers": [],
  "requestMessage": null,
  "isSuccessStatusCode": true
}

Maybe I'm misinterpreting how I should be handling this data, but I feel like this should be getting returned from the Web API call since I explicitly add it.

I have the following Model:

   public class HelpApplication  {  
    public int Id { get; set; }
    public string ApplicatonName { get; set; }     
    public int DisplayOrder { get; set; }  
    public bool Available { get; set; }
    public ICollection<HelpArea> HelpAreas { get; } = new List<HelpArea>();
}

public class HelpArea {
    public int Id { get; set; }
    public string AreaName { get; set; }
    public int DisplayOrder { get; set; }
    public bool Available { get; set; }
    public int ApplicationId { get; set; }
    public virtual HelpApplication HelpApplication { get; set; }
    public ICollection<HelpTopic> HelpTopics { get; } = new List<HelpTopic>();
}

public class HelpTopic  {
    public int Id { get; set; }
    public string Title { get; set; }
    public int DisplayOrder { get; set; }
    public string Content { get; set; }
    public bool Available { get; set; }

    public int AreaId { get; set; }
    public virtual HelpArea HelpArea { get; set; }

    public ICollection<HelpArticle> HelpArticles { get; } = new List<HelpArticle>();
}

 public class HelpArticle {
    public int Id { get; set; }
    public string Title { get; set; }
    public int DisplayOrder { get; set; }
    public string Content { get; set; }
    public string Keywords { get; set; }
    public bool Available { get; set; }
    public int HelpfulYes { get; set; }
    public int HelpfulNo { get; set; }
    public int TopicId { get; set; }
}

and I want to use something like the query below, With HelpArticles, I need only 3 properties. I don't need to pull Content(A CLOB) all the time except when needed.

this.Entities
            .Include(h => h.HelpTopics)
            .ThenInclude(s => s.HelpArticles.Select(t => new { t.Title, t.Keywords, t.DisplayOrder} ))
            .Where(h => h.ApplicationId == appId).ToList();

The above query returns an exception:

The property expression 's => {from HelpArticle t in s.HelpArticles select new <>f__AnonymousType12`3(Title = [t].Title, Keywords = [t].Keywords, DisplayOrder = [t].DisplayOrder)}' is not valid. The expression should represent a property access: 't => t.MyProperty'.

I'll like to return the following :

all properties in HelpApplication;

HelpTopic Title, DisplayOrder, Available,

HelpArticle Title, DisplayOrder, Available, Keywords

JWT is passed in Authorization header in GET request like this:

Authorization: Bearer <token here>

Using trial and error I figured out that header value limit must be around 2048, because requests with tokens smaller than that are passed to my ASP.NET app without any changes and requests with larger tokens have Authorization header removed triggering 401 in my app.

App is published to Azure. It doesn't seem to matter whether request is GET or POST.

Limit looks similar to querystring limit so I've increased the allowed query string and it didn't help.

IIS version: 8.0 (from response headers)

Python chunks uploads into 8192 bytes.

When uploading to IIS 7.5 Python always hangs (on SockWaitForSingleObject) after only 8192 * 680 = 5'570'560 bytes, until a server timeout leads to a disconnection.

If I change that blocksize in Python's httplib.py to 81920, the hang is postponed to 81920 * 468 = 38'338'560 bytes.

If I pass a str instead of a read()-able I avoid the chunking entirely and can upload any size that fits into memory.

IIS is already configured to allow much larger maxRequestLength, maxAllowedContentLength and maxRequestEntityAllowed. The IIS timeout is also much larger than required and only hit because Python hangs.

IIS Failed-Request-Log is silent on the matter.

  • Python2 and Python3 both trigger the exact same problem.
  • Uploading with C# does not trigger the problem.
  • IIS on Windows 10 does not seem to have the problem.
  • IIS Express 8 on Windows 7 does have the same problem.
  • IIS Express 8.5 on Windows 10 does not seem to have the problem.

Any ideas what the problem could be? Is it a Python problem? IIS? Windows 7? How would you debug this?

Imagine a controller action like:

public async Task<IActionResult> Ask()
{
    ...
    ViewData["MyItems"] = Enumerable.Empty<MyItem>();
    return View();
}

And a view like:

@{
    var myItems = ViewData["MyItems"] as IEnumerable<MyItem>
}

@foreach (var item in myItems) <-- this throws null reference exception
{
     <div>@item.SomeProp</div>
}

        <div>
          Projects
            @Html.DropDownListFor(m => Model.ProjectMasterId, new MultiSelectList(Model.ProjectsList, "Value", "Text", Model.ProjectMasterId),
           new { @class = "chosen-projects", multiple = "multiple" })
        </div>
        <div class="button" style="padding-left:18px">
            <input type="submit" class="btn-sm btn-warning" value="Search" name="Search" />`enter code here`

        </div>

Here i have the data from the model and enumerated it using lists

 <script type="text/javascript">
    $(document).ready(function () {
        $(".chosen-projects").chosen({ width: "85%" });
    });
   </script>

The script for jquery chosen

I am unable to see the values that i selected after the submit button is clicked, i need to see the values that i have selected but are gone after the page refresh,

I have searched many but an explanation would be very helpful since i am new to this whole.

I have a database called news and have a column called description, I have two take the Last two entries from table (description column) and display the result as a single string string , ie, want to append the data in the Second last column to the last data. But I am not able to append the text,and deleted the code.

controller

    public ActionResult Index()
    {
        var news = db.News.OrderByDescending(u => u.Id).FirstOrDefault();
        return View(news);
    }

view

@model ThaniyamBank.Models.News

<a href="@Url.Action("NewsInnerPage", "News")">
                    <marquee>
                        <p>
                            @Html.Raw(Model.Description)                                
                        </p>
                    </marquee>
                </a>

sql column

enter image description here

I want to get the value from table last two entries as a single string . can anyone please help me to write the code . how can i append string ???

I need to print all the code under my question

if there is data in @store.GuaranteePolicy print all the <tr>. If there is no data, then print nothing.

No matter if there is data in or not in @store.GuaranteePolicy, then "Payment" is always printet, but why?

I said that if (store.GuaranteePolicy is different than null, then print)

The if statement is working with this:

  • If there is data in store.GuaranteePolicy everything is printed perfect
  • If there is no data in store.GuaranteePolicy the text is not printed, BUT the word Payment: is printed. So the whole <tr> is printed even if it is not true?

    @if (store.GuaranteePolicy != null) { 
    <tr>
        <th class="small-12 large-6 columns first">
            <table>
                <tr>
                    <th width="300">
                        <p class="text-left small-text-left"><strong>Payment:</strong></p>
                    </th>
                </tr>
            </table>
        </th>
        <th class="small-12 large-6 columns last">
            <table>
                <tr>
                    <th width="300">
                        <p class="text-left small-text-left">
                            <span>@store.GuaranteePolicy</span>
                        </p>
                    </th>
                    <th class="expander"></th>
                </tr>
            </table>
        </th>
    </tr>
    }
    

I am using asp.net mvc4.

I am working with DLL so I have to override the classes to extend new methods.

I have a view like this:

@model SalesAgentLoginInfoModel
<div class="top-dropdown login">
    <div class="opener collapsed">
        <span class="login-title">@Sana.SimpleText("Account")</span>
    </div>
    <div class="summary">
        <div class="welcome border-horizontal">
            @Sana.SimpleText("Login_Welcome")
            <span class="user-name">@Model.Name</span>
        </div>
        <a href="@Url.Sana.MyAccount()" class="hyp">@Sana.SimpleText("Login_MyAccount")</a>

        <a href="@Url.Sana.RepresentCustomer()" class="hyp">@Sana.SimpleText("ButtonText_RepresentCustomer")</a>

        <a href="@Url.Sana.RepresentCustomer()" class="hyp">@Sana.SimpleText("ButtonText_baliecode")</a>
        dlkfnslkdf
        <div class="logout border-horizontal">
            <a id="logoutLink" href="@Url.Sana.Logout()" class="arrow-blue">@Sana.SimpleText("Logout_LinkText")</a>
        </div>
    </div>
</div>

And the RepresentCustomer() is from this class:

     // Summary:
        //     The web shop URLs constructor.
        public class UrlsBuilder
        {


 public virtual string RepresentCustomer(string returnUrl = null);
        //
        // Summary:
        //     Gets the URL to the reset password page.
        //
        // Returns:
        //     The reset password page URL.
            //
            // Summary:
            //     Initializes a new instance of the Sana.Commerce.Web.Routing.UrlsBuilder class.
            //
            // Parameters:
            //   routes:
            //     The route collection.
            public UrlsBuilder(RouteCollection routes);

            //
            // Summary:
            //     Gets the instance of Sana.Commerce.Web.Routing.UrlsBuilder.
            public static UrlsBuilder Current { get; }
            //
            // Summary:
            //     The routes used to construct URLs.
            public RouteCollection Routes { get; protected set; }

            //
            // Summary:
            //     Gets the URL to the add review page.
            //
            // Parameters:
            //   productId:
            //     The product ID.
            //
            //   returnUrl:
            //     The return URL.
            //
            //   navigationNodeId:
            //     The navigation node ID.
            //
            // Returns:
            //     The add review page URL.
            public virtual string AddReview(string productId, string returnUrl = null, string navigationNodeId = null);
    }

So I have extended the class UrlsBuilder with a new method like this:

 public class V_ExtendendURlsBuilder : UrlsBuilder
    {
        public V_ExtendendURlsBuilder(RouteCollection routes) : base(routes)
        {
        }

        public virtual string BaliecodeVerkoper( string url)
        {

            return url;

        }
}

But If I try in the view to call the new method like this:

 <a href="@Url.Sana...." class="hyp">@Sana.SimpleText("ButtonText_baliecode")

I don't see the new method BaliecodeVerkoper.

One more thing. The public UrlsBuilder Sana { get; }

is within this class:

 public class FrontendUrlHelper : SanaUrlHelper
    {
        //
        // Summary:
        //     The facet values query string separator.
        public const string FacetValuesSeparator = "\n";

        //
        // Summary:
        //     Initializes a new instance of the Sana.Commerce.Web.Frontend.FrontendUrlHelper
        //     class.
        //
        // Parameters:
        //   requestContext:
        //     The request context.
        public FrontendUrlHelper(RequestContext requestContext);

        //
        // Summary:
        //     Gets the Sana URLs builder.
        public UrlsBuilder Sana { get; }

        //
        // Summary:
        //     Creates a new instance of the frontend URL helper initialized with the specified
        //     requestContext. It can be a standard helper class or a customized version if
        //     it is registered through the Sana.ObjectManager.
        //
        // Parameters:
        //   requestContext:
        //     The request context.
        //
        // Returns:
        //     Returns a new instance of the frontend URL helper.
        public static FrontendUrlHelper Create(RequestContext requestContext);
        //
        // Summary:
        //     Reads the selected facets from the query string of the current request.
        //
        // Parameters:
        //   facets:
        //     The collection of all available facets.
        public void ReadSelectedFacets(FieldFilterCollection facets);
        //
        // Summary:
        //     Sets the selected facets in the query string of the specified url.
        //
        // Parameters:
        //   url:
        //     The base URL.
        //
        //   facets:
        //     The facets.
        //
        // Returns:
        //     Returns the url with the selected facets in its query string.
        public virtual string SetSelectedFacets(string url, FieldFilterCollection facets);
        //
        // Summary:
        //     Reads the selected facets from the specified query string dictionary.
        //
        // Parameters:
        //   queryString:
        //     The query string.
        //
        //   facets:
        //     The facets.
        protected virtual void ReadSelectedFacets(NameValueCollection queryString, FieldFilterCollection facets);
        //
        // Summary:
        //     Sets the selected facets into the queryString.
        //
        // Parameters:
        //   queryString:
        //     The query string dictionary.
        //
        //   facets:
        //     The facets.
        protected virtual void SetSelectedFacets(NameValueCollection queryString, FieldFilterCollection facets);
    }

So my question: how to extend the UrlsBuilder with the new method?

Thank you

a other try is to try it like this:

public class V_ExtendendURlsBuilder : UrlsBuilder
    {
        public V_ExtendendURlsBuilder(RouteCollection routes) : base(routes)
        {
        }

        public virtual string BaliecodeVerkoper( string url)
        {

            return url;

        }



    }

But I still don't see then the new method:

 public class ExtendFrontEndUrlHelper : FrontendUrlHelper
    {
        public UrlsBuilder builder;
        public ExtendFrontEndUrlHelper(RequestContext requestContext) : base(requestContext)
        {
        }

        public UrlsBuilder BalieCode()
        {

            return builder;

        }
    }

I just want to extend the class UrlsBuilder with a new method Baliecode. So that I can use the method in the view. But UrlsBuilder is an DLL. So I have to extend the class with a new method.

I hope I am clear now.

See my image. So I still don't see the new method Baliecode

Thank you

enter image description here

but how to use it in the view then?

<a href="@Url." class="hyp">@Sana.SimpleText("ButtonText_baliecode")</a>

@Url.. and then?? I don't see the extended...

if I go to:

<a href="@Url.Sana" class="hyp">@Sana.SimpleText("ButtonText_baliecode")</a>

and then f12 on @Url

I see this class:

public abstract class SanaWebViewPage : SanaWebViewPageBase
    {
        protected SanaWebViewPage();

        //
        // Summary:
        //     Gets the Sana view helper.
        public SanaViewHelper Sana { get; set; }
        //
        // Summary:
        //     Gets or sets the Sana.Commerce.Web.Frontend.FrontendUrlHelper object that is
        //     used to manage the URLs.
        //
        // Returns:
        //     The current Sana.Commerce.Web.Frontend.FrontendUrlHelper.
        public FrontendUrlHelper Url { get; set; }
        //
        // Summary:
        //     Gets the page info.
        protected virtual WebPageInfo PageInfo { get; }

        //
        // Summary:
        //     Initializes the helpers.
        public override void InitHelpers();
    }

Oke, I have it now ,like this:

 public class extendedSanaWebviewPage : SanaWebViewPage
    {
        public ExtendFrontEndUrlHelper extendedFrontEndUrlHelper { get; set; }

        public override void Execute()
        {
            throw new NotImplementedException();
        }
    }

But I don't see in the view: @extendedFrontEndUrlHelper

Thank you

I am creating a bot application using Microsoft Bot Framework and want to localize the bot with multiple languages. I have created resource files but I don't know how to proceed with setting the culture. I know about Localizing MVC Web Application but I am not getting how do I do this for the Dialogs in Bot Application.

I am trying to get the cell data from a GridView, however i can access the first cell and get the data, however when i try and access the 2nd cell I get a blank string back. This happens under a click event.

public void btnBCM_ClickbtnSaveBCM_Click(object sender, EventArgs e)
 {
   String value = GridView_Products.Rows[0].Cells[1].Text;
 }

GridView Image below

enter image description here

How to select folder in ASP.net using HttpFileCollection

I need to select a folder in web application then need to retrieve all the files name in that folder

In ASP.net web application how to do

I did the below coding but getting only files can't select the folder

HttpFileCollection uploadedFiles = Request.Files;

for (int i = 0; i <= uploadedFiles.Count - 1; i++)
{
    HttpPostedFile userPostedFile = uploadedFiles[i];
    ------
}

I created a default asp.net MVC Project in Visual Studio 2015 to get all the Authentication Goodness by default. Now I try to create an 3 Layer architecture with an DataAccess Layer and would use the same DB for the authentication as for the other data. I would usually put the DbContext in the DataAccess Layer. But since OWIN needs in on startup this doesn't really work, since I would have to access the Data Access Layer from the view layer.

Is there some best practice how to structure the project with OWIN authentication enabled? Or should I just make one project who contains everything (which sounds ab it messy) or use an other db for the data than for the authentication?

I am setting up an AspMVC 4.5 application running on an IIs 7 server on the local network, i cant acces the site in my brower after publishing it can acces the routei get: HTTP Error 500.19 - Internal Server Error Module IIS Web Core Notification BeginRequest Handler Not yet determined Error Code 0x80070021

after editing i get:

HTTP Error 403.14 - Forbidden problem with system.webserver Module DirectoryListingModule Notification ExecuteRequestHandler Handler StaticFile Error Code 0x00000000

When I try to connect them. It shows error: The database is version 782, VS 2010 supports version 655 and below. What should I do in such situation please guide me. I'm mentally frustrated coz of this!

I'm using a razor mvc view with a @Html.HiddenFor(), but after postback a custom property value of model always returns null.

Property: public Survey Survey { get; set; }

Here my hidden field:

@html.hiddenValueFor(x => x.Survey);

Here my Model:

public class Response
{
    [Key]
    public int Id { get; set; }
    public int SurveyId { get; set; }
    public Survey Survey { get; set; }
    public string CreatedBy { get; set; }
    ....
}

I am using DropZone for file Upload, regarding this i am unable to get uploading **filepath in "addedFile" event, So any help and suggestions will be really appreciable.

Thank you in Advance

I was tasked to automate a small tool using Web Forms.

We have figured out that deploying it into a web server would not be worth it since the application is only comprised of one .aspx page, playing around with UpdatePanels, exporting the required PDF with the consolidated numbers, etc. No database was involved. The calculations are done on postbacks.

Is it possible to create an installer instead? Like the idea of being able to use the app after they run the installer that they received?

Or only deploying locally is the ONLY work around on hosting it on a web server?

My team won't be using the automated tool. We automated the task so that the requestor could generate the results on their own using the tool. It is also my first time deploying a project.

Thank you very much!

I have directory @"c:\dom\" where I have more than 100 excel files. I need to return all the excel file path in below format(CSV)

@"C:\dom\dom1.xlsx", @"C:\dom\dom2.xlsx", @"C:\dom\dom3.xlsx", . . . @"C:\dom\dom100.xlsx"

I tried the below

 string[] array1 = Directory.GetFiles(@"C:\Users\dom\");
 foreach (string name in array1)
 {
    string.Join(",", name);
 }

It didn't work out.

I have products and each product has a ticket category. I want a count of products by category. I tried this LINQ query:

var categoriesQuery = from cat in db.Category
                      join p in db.Product on cat.CategoryID equals p.CategoryID
                      group cat by cat.CategoryName into catGroup
                      select new
                      {
                          CategoryType = catGroup.Key,
                          NumberOfProducts = catGroup.Count()
                      };

This returns the first category and the total number of products (not just the count for that category). How do I get all categories and count of products for each?

For instance:

Produce    5
Deli       6
Frozen     9

It seems a very simple issue but it has killed my day. I have an update-able gridview and I put a dropdownlist in the edit mode of one of the columns. The items in the DDL is statically set. BUT the selected item always remains the first item. How can I fix this?

   protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string userID = ((Label)GridView1.Rows[e.RowIndex].FindControl("lbluserID")).Text;

        string role = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1")).SelectedValue;


        SqlCommand cmd = new SqlCommand();
        cmd.Connection = DBSettings.sqlConn;
        cmd.CommandText = "Update tbl_users set role=@role , pending='false' ,approved='true' , declined='false' where ID=@ID";
        cmd.Parameters.AddWithValue("@role", role);
        cmd.Parameters.AddWithValue("@ID", userID);
        cmd.ExecuteNonQuery();
        GridView1.EditIndex = -1;
        gridFill();

    }

here is the aspx of the gridView (only the ddl part):

  <asp:TemplateField HeaderText="Role">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                        <asp:ListItem Value="">--Select--</asp:ListItem>
                        <asp:ListItem Value="Admin" Text="Admin">           </asp:ListItem>
                        <asp:ListItem Value="Editor" Text="Editor">    </asp:ListItem>
                        <asp:ListItem Value="Viewer" Text="Viewer">     </asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text="pending"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>