I have a standalone WebAPI Application that returns a token when authenticating against it. When I make calls back to the API and send the token in the header the API is able to retrieve the claims and roles of that token.

However when I consume that API and get the token in a separate MVC Application I only have access to some limited properties like the access_token, token_type, expires_in, etc.

Is it good practice to return custom claims and user roles in that response result? Or should I make an additional call to the API to return the user claims and user roles and update the existing token?

I am building a search page using asp.net mvc. The page would have two text search fields and few search parameters based on checkbox and radio button. How can I maintain the state of checkboxes and radio button once the result comes back ? Some of these checkboxes may be dynamically generated too.

I have a View whose model is a List of custom types and I want to POST changes for only a single element of the List (model[i]). This POST itself works, except the value is what was originally in the model and not the updated value from the input

View's Model Declaration

@model List<Translation2>

Translation2's type (F#)

type Translation2 = {
    Key: string;
    RowKey: string;
    Value: string;
    English: string;
}

The View with a single entity submit

@model List<Translation2>

<form asp-controller="Home" asp-action="Translate" method="POST" >
<table>
    <thead>
        <th>
            <h2>Key</h2>
        </th>
        <th>
            <h2>English</h2>
        </th>
        <th>
            <h2>Translated</h2>
        </th>
    </thead>
    <tbody>
@for(var i = 0; i < Model.Count(); i++)
{
        <tr>
            <div>
                <td class="key-col">
                    <p style="font-size:large">@Model[i].Key</p>
                    @Html.HiddenFor(m => m[i].RowKey)
                </td>
                <td class="val-col">
                    <input class="fill-void" type="text" asp-for="@Model[i].English" readonly />

                </td>
                <td class="val-col">
                    <input class="fill-void" type="text" asp-for="@Model[i].Value" />
                </td>
                <td>
                    <a href="@Url.Action("Translate", "Home", new {RowKey=@Model[i].RowKey, Key=@Model[i].Key, Value=@Model[i].Value })" >Save Translation</a>
                </td>
            </div>
        </tr>
}
    </tbody>
</table>
</form>

I have also tried to just POST the entire list per ASP.NET Core 1.0 POST IEnumerable<T> to controller but will get

ArgumentNullException: Value cannot be null.
 Parameter name: source

Count

MoveNext in Translate.cshtml

@for(var i = 0; i < Model.Count(); i++)

The View with submitting the entire list

@model List<Translation2>

<form asp-controller="Home" asp-action="Translate" method="POST" >
<table>
    <thead>
        <th>
            <h2>Key</h2>
        </th>
        <th>
            <h2>English</h2>
        </th>
        <th>
            <h2>Translated</h2>
        </th>
    </thead>
    <tbody>
@for(var i = 0; i < Model.Count(); i++)
{
        <tr>
            <div>
                <td class="key-col">
                    <p style="font-size:large">@Model[i].Key</p>
                    @Html.HiddenFor(m => m[i].RowKey)
                </td>
                <td class="val-col">
                    <input class="fill-void" type="text" asp-for="@Model[i].English" readonly />

                </td>
                <td class="val-col">
                    <input class="fill-void" type="text" asp-for="@Model[i].Value" />
                </td>
                <td>
                    <button type="submit">Save Translation</button>

                </td>
            </div>
        </tr>
}
    </tbody>
</table>
</form>

I would really like to know how to solve both ways, if possible, but a solution for either will do at this point.

    here is my .aspx code !

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;

    public partial class _Default : System.Web.UI.Page
    {
        int id;
        protected void Page_Load(object sender, EventArgs e)
        {
            Label2.Text = " " + Session["username"] + " ";
            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {
                id = Convert.ToInt32(Request.QueryString["Prod_Id"].ToString());
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from Product  where Prod_Id="+ id +"";
                cmd.ExecuteNonQuery();
                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                Repeater1.DataSource = dt;
                Repeater1.DataBind();
                con.Close();

            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "insert into Order values('" + Label2.Text + "','"+ label3.Text +"')";
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }

    }

here is my.aspx code

<%@ Page Title="" Language="C#" MasterPageFile="~/welcome_mstr.master" AutoEventWireup="true" CodeFile="desc.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">



&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <b>Welcome</b>



<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
&nbsp;!<asp:Repeater ID="Repeater1" runat="server" 
        onitemcommand="Repeater1_ItemCommand">
<HeaderTemplate></HeaderTemplate>
    <ItemTemplate>

       <div style=" width:700px; margin-left:200px; background-color:#FCFBE3">

       <br />

       <table>

       <tr><td><img alt="" src='<%# Eval("Image") %>' style=" width:299px; height:299px;" /></td>


        <td valign="top"><table >
        <tr><td align="left"><asp:Label ID="Label3" runat="server" Text='<%#Eval("Prod_Name") %>'></asp:Label></td></tr>


        <tr><td align="left"><asp:Label ID="Label4" runat="server" Text='<%#Eval("Weight") %>'></asp:Label></td></tr>


       <tr><td align="left">Cost: ₹<asp:Label ID="Label1" runat="server" Text='<%#Eval("Price") %>'></asp:Label></td></tr>
       <tr><td>
           <asp:Button ID="Button1" runat="server" Text="Order" /> </td></tr>
       </table>
       </td>
       </tr>

       </table>
       </div>



        </ItemTemplate>
        <FooterTemplate></FooterTemplate>
    </asp:Repeater>

</asp:Content>

I want to use the 'Text' property of a control inside Repeater control and insert that text value into a table through button click. But i am not able to access the control it self. Its showing an error "The name 'label3' does not exist in the current context".How do I do it ? PLEASE HELP !?

I am attempting to deploy a .NET Core app on Ubuntu 16.04. The project contains references to other projects (i.e. not via nuget), locally the app works fine (win10-x64) however on the server when typing dotnet restore I receive the following log:

XXXXXX@ip-172-31-34-212:/home/XXXXXX$ dotnet restore
    log  : Restoring packages for /home/XXXXXX/project.json...
    error: Unable to resolve 'XXXXXX.Configuration (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'.
    error: Unable to resolve 'XXXXXX.DataModels (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'.
    error: Unable to resolve 'XXXXXX.DAL (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'.
    error: Unable to resolve 'XXXXXX.Application (>= 1.0.0-0)' for '.NETCoreApp,Version=v1.0'.
    error: Unable to resolve 'XXXXXX.BLL (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'.
    log  : Lock file has not changed. Skipping lock file write. Path: /home/XXXXXX/project.lock.json
    log  : /home/XXXXXX/project.json
    log  : Restore failed in 4546ms.

log  : Lock file has not changed. Skipping lock file write. Path: 

I have reviewed the advice in the related questions here, here and here however none of the solutions seem to fix my issue.

Given the pace of change to the Core framework I will specify the versions in use and the project.json files for the projects:

XXXXXX.Configuration (.NET Core Class Library) project.json:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.1"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

XXXXXX.DataModels (.NET Core Class Library) project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.1",
    "XXXXXX.Application": "1.0.0-0"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

XXXXXX.DAL (.NET Core Class Library) project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "MySql.Data": "7.0.6-IR31",
    "NETStandard.Library": "1.6.1",
    "XXXXXX.Application": "1.0.0-0",
    "XXXXXX.Configuration": "1.0.0-*",
    "XXXXXX.DataModels": "1.0.0-*"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

XXXXXX.Application (.NET Core Class Library) poject.json

{
  "version": "1.0.0-0",

  "dependencies": {
    "Microsoft.AspNetCore.Mvc.Abstractions": "1.1.0",
    "Microsoft.AspNetCore.Mvc.Core": "1.1.0",
    "Microsoft.AspNetCore.Mvc.DataAnnotations": "1.1.0",
    "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.1.0",
    "MySql.Data": "7.0.6-IR31",
    "NETStandard.Library": "1.6.1",
    "System.Data.SqlClient": "4.3.0"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

XXXXXX.BLL (.NET Core Class Library) project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.Extensions.Configuration.Binder": "1.1.0",
    "NETStandard.Library": "1.6.1",
    "XXXXXX.Application": "1.0.0-*",
    "XXXXXX.Configuration": "1.0.0-*",
    "XXXXXX.DAL": "1.0.0-*",
    "XXXXXX.DataModels": "1.0.0-*"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

And finally, the .NET Core Web UI proejct which ties it all together:

XXXXXX.WebUI project.json

{
  "dependencies": {
    "BundlerMinifier.Core": "2.3.327",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Mvc": "1.1.1",
    "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Routing": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Session": "1.1.0",
    "PaulMiami.AspNetCore.Mvc.Recaptcha": "1.1.1",
    "Microsoft.AspNetCore.Mvc.Abstractions": "1.1.1",
    "Microsoft.Extensions.Options": "1.1.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
    "XXXXXX.DataModels":  {
        "version":"1.0.0-*",
        "target": "project"
    },
    "XXXXXX.Application": {
        "version": "1.0.0-0",
        "target": "project"
    },
    "XXXXXX.Configuration": {
      "version": "1.0.0-*",
      "target": "project"
    },
    "XXXXXX.DAL": {
        "version": "1.0.0-*",
        "target": "project"
    },
    "XXXXXX.BLL": {
         "version": "1.0.0-*",
         "target": "project"
    }
  },

  "tools": {
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "copyToOutput": [ "web.development.environment.json" ]
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "runtimes": {
    "win10-x64": {},
    "ubuntu.16.04-x64":  {}
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config",
      "global.json",
      "project.json",
      "web.development.environment.json"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

I also have a global.json which when published resides in the root folder (one level above the projects)

{
  "projects": [ 
    "src", 
    "/home/XXXXXX/XXXXXX.Application.dll", 
    "/home/XXXXXX/XXXXXX.Configuration.dll", 
    "/home/XXXXXX/XXXXXX.DataModels.dll", 
    "/home/XXXXXX/XXXXXX.Common.dll",
    "/home/XXXXXX/XXXXXX.BLL.dll", 
    "/home/XXXXXX/XXXXXX.DAL.dll", 
    "/home/XXXXXX/XXXXXX.Notifications.Client.dll", 
    "/home/XXXXXX/XXXXXX.Notifications.DataModels.dll",
    "/home/XXXXXX/XXXXXX.WebUI.dll"
  ]
}

Help!

I'm working on the security part of one of the upcoming websites developed based on ASP mvc. Here the target is like below.

I enter say localhost:12345 I get redirected to localhost:1234/Login, But my requirement is as below.

Every time an user enters localhost:12345, it should create a random number and it should be shown to user as localhost:12345/{hereIsTheRandomAlphaNumericStringGenerated}, for example say user 1 is logged in, he is having the url as localhost:12345/user!Rand123 and there is another user logged in and his URL should be localhost:12345/a12fer43r5. if someone enters this randomly generated URL to their web page, it should give an error. The base underying URL should be the same Login, but the names should be generated randomly. And also, if the user enters localhost:12345/login even in this case, the user should not be permitted.

in my RouteConfig.cs I've the below code available.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace ComplianceBot
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new
                {
                    controller = "Home",
                    action = "Login",
                    id = UrlParameter.Optional
                }
            );
        }
    }
}

Please let me know how can I do this.

I am working on a simple ASP.NET web application with a server and a bunch of clients connected to it. The application is for a LAN environment. There are some third part websites that have usernames and passwords that are not to be shared with the clients. Is there a way to maintain a login session to these websites and share these sessions with the clients on request? If Yes, then how can it be achieved? I have a feeling this can be done using a proxy server somehow. Any kind of help is appreciated.

PS: I am primarily an ASP.NET developer and am building the project using C# as the scripting language.

Is there a way to make a database connection without using web config file ?

I use vbnet (razor) (.vbhtml) webforms

my connectionstring is

<connectionStrings>
    <add connectionString="Server=LAPTOP-Bilo\SQLEXPRESS;Trusted_Connection=True;Database=kees" name="kees" providerName="System.Data.SqlClient" />
</connectionStrings>

I have 2 different models, Persons and Blocks and both have the same properties, ProjNr. And I am using dynamic model in the View. Now in the Razor view I want to check if the ProjNr from Blocks has already the ProjNr from Persons and if so show a text, and if not show a button.

How to make a comparison between 2 different models when using dynamic model?

My goal is to create a new database for new brands that the user will add on the website. I've created a code for doing such task but it is giving me this exception: An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code Additional information: Incorrect syntax near 'char'.

I already looked at the code several times but i still can't find the root cause of the problem.

Here is the code:

public static void CreateGuitarBrandsDatabase(string brand)
{
    SqlConnection createBrandData = new SqlConnection(@"Data Source=Y560\SQLEXPRESS;Initial Catalog=GuitarItemsDB;Integrated Security=True");
    createBrandData.Open();
    SqlCommand cmdBrandData = new SqlCommand("CREATE TABLE guitarItem" + brand + "(id int,type char(50),model char(50),price float,image1 char(255),image2 char(255),description text,neck type char(100),body char(100), fretboard char(100),fret char(50),bridge char(100),neck pickup char(100),bridge pickup char(100),hardware_color char(50));", createBrandData);
    cmdBrandData.ExecuteNonQuery();//The exception seems to be pointing right here
    createBrandData.Close();
}

I have enabled gzip in IIS. From the failed requesst log I can see dynamic compression is sucess.But the content encoding is not present in response headers.Please suggest a solution, see the settings below. Response Header

HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Date: Thu, 16 Feb 2017 16:12:04 GMT
Transfer-Encoding: chunked

Request Headers

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Content-Length:68
Content-Type:application/json; charset=UTF-8

DYNAMIC_COMPRESSION_START GENERAL_SET_RESPONSE_HEADER HeaderName="Vary", HeaderValue="Accept-Encoding", Replace="false" DYNAMIC_COMPRESSION_SUCCESS DYNAMIC_COMPRESSION_DO OriginalSize="266271", CompressedSize="30223" DYNAMIC_COMPRESSION_END

web.config compression settings

I have some values that are set on a master page and that I want to save across a postback. I then want these variable to be available to pages using that master page during their load events.

Easy enough to create properties on the master page. So my first try to was to say that during the master page's load event, if not ispostback then generate the values and save them to the viewstate, else read them from the viewstate.

Except ... apparently the regular page load event happens BEFORE the master page load event, so the data wasn't there yet when I tried to read it.

Second try: have the master page set or retrieve these values during the Init event. No luck. Appears that the view state is not populated by Init time.

As far as I can tell, there's no event on a master page that happens after view state is populated but before the main page's Load event.

I suppose each page could have an InitComplete or PreLoad that calls a function to populate these fields, but that seems really clumsy. The call would have to be in every page. And it would have to be in every page even if that page never used this data, because the master page uses the data for its own purposes.

Is there a way to do this? Maybe view state is not the right place to save the data? I could store the data in Session variables, but then on not-postback the data in them would be left over from the last call. I guess I could make sure to clear the obsolete data, but that seems really clumsy.

I'm writing in VB but I wouldn't think that would make a difference here.

Right now I have a list of checkboxes inside a panel using:

            <div style="float:right; position:relative; ">
                <Label><span style="font-weight:normal; font-size:16px;">Box1</span> @Html.CheckBoxFor(modelItem => item.b1)</Label>
            </div>
            <div style="float:right; position:relative; ">
                <Label><span style="font-weight:normal; font-size:16px;">Box2</span> @Html.CheckBoxFor(modelItem => item.b2)</Label>
            </div>
            <div style="float:right; position:relative; ">
                <Label><span style="font-weight:normal; font-size:16px;">Box3</span> @Html.CheckBoxFor(modelItem => item.b3)</Label>
            </div>

However, sometimes the checkboxes don't stay in their each individual lines and instead they jump onto the same line as another checkbox. E.g. I want it to be formatted into

Box1

Box2

Box3

But occasionally it becomes:

Box1 Box2

Box3

How can I fix this??

I am somewhat of a beginner and would like someone to please help me understand how Angular 2 ties into .net Core when building a web application.

I just read Adam Freeman's Pro MVC Core book, where he build a sports store using entity framework and generating razor views to display all information. I am now trying to learn Angular 2 so I can learn the front end better, and it seems like all I learned using MVC Core Razor is now a waste. What is the common usage of these technologies together? If I build a SPA using Angular 2, could I access the database using a web api built from .net core? Is that the common usage? Or is there a way to build a .net core application using entity, using normal controllers that generate angular views instead all in visual studio? I guess they would not be cshtml files? Please help me understand this.

Lastly, I am using .net code with Angular, should I be using visual studio instead if I want to use .net on the back end? Thank you.

I have a couple of websites running on .net 3.5 still due to an API restriction. We will eventually move these sites to the latest .net version this year. One of the penetration tests indicated a possible XSS vulnerability. The URL in question is:

Location: http://www.foobar.com/basket.aspx/scripts/searchresults.aspx

Method: GET

Vulnerable Parameter: name of an arbitrarily supplied URL parameter

Basically, anything after basket.aspx like scripts/searchresults.aspx will cause the issue. From what I can determine, Request.PathInfo will try to find the path and eventually reach searchresults.aspx (if the .aspx page exists) but all my css and scripts can't be found due to relative paths. The page essentially breaks. It's unclear how this could cause an XSS vulnerability. Nevertheless, it does break the page.

My questions are; Is Request.PathInfo needed? In my preliminary tests, if I check Request.PathInfo, I can determine that it may be a bad URL request:

FooBar.Global pageObj = obj;

if (obj.Request.PathInfo.Length > 0)
{
   Response.Redirect("~/sitemap.aspx", true); // bad url send to site map
}

I want to log a user into an ASP MVC site , and the session expires very quickly, in minutes. Authentication is done in one line of code:

authProvider.Authenticate(model.UserName, model.Password)

Then I have in Webconfig:

<authentication mode="Forms">
<forms loginUrl="~/Account/Login" name=".ASPXAUTH" timeout="300" slidingExpiration="true"> 

and the setting on the IIS on the server for 300 minutes.

What is the problem? Thanks

I have a login form inside a #myModal body. The logging in functionality is fine except that if the incorrect username and password are entered, it does not redirect to the #myModal with the respective error messages. It instead redirects to the default login page. I don't know how to redirect to the modal instead of the default login page.

Modal

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
        </div>
        <div class="modal-body">
            <section id="loginForm">
                @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
                {
                    @Html.AntiForgeryToken()
                    <h4>Use a local account to log in.</h4>
                    <hr />
                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                    <div class="form-group">
                        @Html.Label("E-mail", new { @class = "col-md-2 control-label" })
                        <div class="col-md-10">
                            @Html.TextBox("email", "", new { @class = "form-control", @placeholder = "Email" })
                        </div>
                    </div>
                    <div class="form-group">
                        @Html.Label("Password", new { @class = "col-md-2 control-label" })
                        <div class="col-md-10">
                            @Html.Password("Password", "", new { @class = "form-control", @placeholder = "Password" })
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-offset-2 col-md-10">
                            <input type="submit" value="Log in" class="btn btn-success" />
                        </div>
                    </div>
                }
            </section>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
</div>

Login Controller method

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (!ModelState.IsValid)
        {
            //how do I redirect back to the login modal if modelstate is invalid?
            return View(model);
        }

        // This doesn't count login failures towards account lockout
        // To enable password failures to trigger account lockout, change to shouldLockout: true
        var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return View(model);
                //how do I redirect back to the login modal?
        }
    }

I need to work with ASP.NET templates in Dreamweaver CC, but is very annoying that asp elements like have the same colors as HTML elements, making very hard to identify dynamic content in a bunch of HTML code. I'm not a programmer, my job is to update to responsive HTML5+CSS3 the markup in a .NET web app made originaly with tables and inline styles (The horror). Dreamweaver CC preferences have options for PHP, Javascript, etc. but not for ASP. Is there a way to work with ASP in Dreamweaver similar to PHP? Any help or guidance would be highly appreciated.

I am trying to receive only a string in my Post Method of wcf rest service . Is that possible . Just a string not an object . I tried but i am getting null not data is coming to my Post method.

Is it possible (and reasonable) to use a fractal based project structure with ASP.Net MVC? If so, would love to see some examples.

I have changed my asp.net website favicon and it works perfectly when navigating through website's pages.

I have put the favicon.png in Views/Shared/_Layout.cshtml file

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="icon" type="image/png" href="~/images/favicon.png" />
  <title>@ViewBag.Title</title>

  @Styles.Render("~/Content/css")
  @Scripts.Render("~/bundles/modernizr")
</head>

However when I open a image in new window my favicon changes back to the asp.net default icon.

<div class="col-sm-12">
    <a href="~/images/holiday/sunset_1.png" target="_blank">
        <img class="img-responsive" src="~/images/holiday/sunset_1.png" />
    </a>
</div>

Does anybody know how to change this or why it happens.

Thanks in advance.