I found that this code would make my page remain at the same position if I refresh the page.

var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
function BeginRequestHandler(sender, args) {
    xPos = $get('scrollDiv').scrollLeft;
    yPos = $get('scrollDiv').scrollTop;
function EndRequestHandler(sender, args) {
    $get('scrollDiv').scrollLeft = xPos;
    $get('scrollDiv').scrollTop = yPos;

However the result is not the same when the page reloads due to form post, is it possible to fix this and make it work for both situations?

I have hosted a ASP.NET WebApi application w/ Angular2 in the front end on godaddy.

On the server I have enabled: Go Daddy Settings

My web.config in the web.api project looks like this:

    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
        <httpRuntime targetFramework="4.5.2" />
    <trust level="Full" />
    <customErrors mode="Off" />
    <authentication mode="None" />
    <compilation targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
      <remove name="FormsAuthentication" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameter value="mssqllocaldb" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

AFTER couple minutes of the application working.. I always get the following login prompt.

Login Prompt

I have tried adding <identity impersonate="true"/> but that didn't do anything.

What am I doing wrong here?

encrypt email and store in database by using sql server now I want to fetch that email and decrypt it then want to show in grid view please give me some solution of my problem

This is my checkBoxList:

<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatColumns="2" Style="float: left; font-size: large;"></asp:CheckBoxList><br />

When i select an item and press the button i gets an error System.IndexOutOfRangeException

I use this line to show selected item


Thank you!

This is my test

I've got a webservice which provide my app from data. Currently I've got issues with dates.

In my Ionic pages i use the date pipe like this: {{model.DateStart | date: 'dd-MM-yyyy HH:mm'}}

This results in '18-02-2017 14:08', thats good.

But when the service sends this '2017-02-18T15:00:00' the result is '18-02-2017 16:00'. That's not good.. It adds a hour somewhere.

It'll have to do with the locale settings somewhere, but I don't know how to fix it.

Anyone knows how to fix this problem?

medicinecenterlist = (List)Session["medicinecenterlist"]; this session has multiple value and MedicineCenter is a moddel and have many property. Now My view page or View template how i fetch/show/retrive all multiple data or array of data in List Box.

i am trying to add the default button functionality for the table each row. in each templates of the list view like Insert template and Edit template.

One way i know is using asp Panel but how will add the panel in each row of the table to get the functionality working and if not panel then what will be the other way of achieving it.

Please help as its very basic requirement from the application which we are stuck with the tables.

I got this error in visual studio 2015 while publishing asp.net.core web app to azure.

The "Publish" task failed unexpectedly. System.Exception: Publishing WebApplication1 for .NETFramework,Version=v4.6.2/win7-x64

Illegal characters in path. Parameter name: path at Microsoft.DotNet.Tasks.Publish.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuild.

the project builds on local machine and launched the web app successfully but fails to deploy on azure.

I am trying to create an ASP.NET MVC Web API project using entity framework

I'm not sure where to start,based on your experience can anyone point to web tutorials I can look up to get started?anyone give me a hand?

If this is not the right forum,where should I post questions like these

So, I've seen this solution (http://www.hanselman.com/blog/HowToEnableHTTPStrictTransportSecurityHSTSInIIS7.aspx) used in other answers and other sites, but I don't understand HOW the HSTS header is being added. I assume it has a lot to do with this:

<match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />

Could someone explain where "RESPONSE_Strict_Transport_Security" is coming from?

Full code:

<?xml version="1.0" encoding="UTF-8"?>
                <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                    <match url="(.*)" />
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
                        redirectType="Permanent" />
                <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
                    <match serverVariable="RESPONSE_Strict_Transport_Security"
                        pattern=".*" />
                        <add input="{HTTPS}" pattern="on" ignoreCase="true" />
                    <action type="Rewrite" value="max-age=31536000" />

I am a total .net beginner and just starting in the world of web development, but I do have a fair amount of database and backend experience using mostly non Microsoft technologies. I'm looking for an example of a current (preferably free) C#.net application template that I can use to do the following:

  1. Display a list of records from a record set in a read only grid on a main webpage.

  2. When the user clicks on a single record/row in the grid, a separate add/edit detail page will be displayed for the record with controls to match the data types of the fields (textboxes, date pickers, etc.)

  3. The user can edit the individual fields on the detail page and click a cancel or save button to update the record and return to the main page

I know this is painfully simple to most of you, but to a noob who is just starting, it's difficult to weed through the many online resources and find a good simple working complete example. Any advice? Thank you!

i am using owin middleware for authentication. I am using 3 middleware extensions eg bearer, custom1, custom2.

After authentication has happened, I want to know in my authhorization code, which of the middleware extension was successful in authenticating. I tried to achieve it by inserting a property in AuthenticationTicket

 Dictionary<string, string> statevalues = new Dictionary<string, string>() { { "successful", "true" } };
AuthenticationProperties props = new AuthenticationProperties(statevalues);
AuthenticationTicket authenticationTicket = new AuthenticationTicket(claimsIdentity, props);

But I couldn't find how to read back these properties. They were not available in HttpContext.Current.GetOwinContext().Authentication.GetAuthenticationTypes() also.

Any idea?

I dont understand the error message. What does it mead by scalar variable? @ASIN value should be stored in the id variable I created for the GetByAsin method.

 //Gets one Music Detail
    public MusicDescriptionModel GetByAsin(string id) 
        using (IDbConnection db = connection)
            string sql = "select ASIN, Title, Artist, Price, ReleaseDate,NumberDisks,label,DetailPageURL, Review" +  
                           "FROM tblDescription WHERE id = @ASIN";
            //need to parameterize ID to avoid sql injection attacks.
            MusicDescriptionModel musicdesc = db.Query<MusicDescriptionModel>(sql, new { id }).SingleOrDefault();
            return musicdesc;

My code used to work before but it stopped working since Salesforce updated from TLS 1.0 encryption protocol to TLS 1.2.

Can you please let me know what modifications i should make in order to my code to work or send information to Salesforce with TLS 1.0 disabled and TLS 1.2 enabled.

This is my code below:

public static string WRequest(string URL, string method, string postData)
  string responseData = "";
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
  request.Accept = "*/*";
  request.AllowAutoRedirect = true;
  request.UserAgent = "http_requester/0.1";
  request.Timeout = 60000;
  request.Method = method;
  if (request.Method == "POST")
   request.ContentType = "application/x-www-form-urlencoded";
   UTF8Encoding encodingutf8 = new UTF8Encoding();
   byte[] postByteArray = encodingutf8.GetBytes(postData);
   request.ContentLength = postByteArray.Length;
   Stream postStream = request.GetRequestStream();
   postStream.Write(postByteArray, 0, postByteArray.Length);
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  if (response.StatusCode == HttpStatusCode.OK)
   Stream responseStream = response.GetResponseStream();
   StreamReader myStreamReader = new StreamReader(responseStream);
   responseData = myStreamReader.ReadToEnd();
  return responseData;

I have setup my HTML in razor like following:

  @if (ViewBag.Added != null)
                                if (ViewBag.Added == false)
                                    <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12" id="wholeBtn">

                                     <a class="btn btn-app btnWatchList" style="min-width:100%;margin:0;height:67px">
                                    <i class="fa fa-save"></i> Add to Watchlist
                                else if (ViewBag.Added)
                                    <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12" id="addedToWatchList" style="padding:10px 0">
                                        <h4 style="text-align:center;margin-top:20px"><i class="fa fa-check" style="color:darkseagreen;font-size:25px"></i> Watching</h4>
                                <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12" id="wholeBtn">

                                    <a class="btn btn-app btnWatchList" style="min-width:175px;margin:0;height:67px">
                                        <i class="fa fa-save"></i> Add to Watchlist

The onclick button looks like this:

$(".btnSaveWatchlist").on("click", function (event) {
       $.post("/User/SaveWatchList", { comment: $('#TextArea1').val(), rating: $('input[name=rating]:checked').val(), competitor: $('.txtSearch').val() }, $(this).prop('disabled', true))
                             .done(function (data) {
                                 if (data == "AllFieldsRequired") {
                                     ShowErrorMessage("All fields are required!");
                                 else {
                                     setTimeout(function () {
                                         var result = $('<div />').append(data).find('#addedToWatchList').html();
                                         var l = document.getElementById('cancelButton');

                                     setTimeout(function () {

So initially this button "Add to watchlist" isn't present in DOM. It is loaded into the DOM after an search is performed on website.

Once that is done, onclick event works very fine. When post is done, I hide the button and update the DOM to show user that he added this user to watchlist.

Performing the search now again on different user that wasnt added to watchlist, and the button "Add to watchlist" with class "btnSaveWatchlist" is again loaded into the DOM.

But this time it is completely unresponsive... I checked whether the action in controller gets initiated, it doesn't ... The button seems like it's "Frozen"...

Any ideas what could it be guys?

P.S. All this is done without refreshing the page at all. I don't want to refresh the page at all for end user...

Edit here is the btnSaveWatchList button with the class:

  <button data-remodal-action="cancel" class="remodal-cancel" id="cancelButton">Cancel</button>
    <button class="remodal-confirm btnSaveWatchlist">Save</button>

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)

                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 found out that with ASP.NET you are able to build a back-end of the website using C# and it look really cool to me, so I wanted to learn it.

The first thing I came across was that there is ASP.NET, ASP.NET Core, ASP.NET MVC and it all confused me. What should I learn, what are the differences, is the code same, if I learn one can I quickly adopt to another?

I just don't know where to start. And if I create a new ASP.NET Core project I just get a bunch of files that I don't know what to do with them.

And can an ASP.NET website be published on a standalone server that is hosted somewhere?

I'm using multiple html controls sharing same name. I have accessed file name and directories of all files, but finding a way to move them to server. Remember my control is not server side. Is there any possible way to upload file to server using the file directory. I search but they are using asp.net file control to upload files. My html code is here

<input type="file" class="form-control" name="signatures" />

Let suppose my file is C:\abc.jpg and I want to move it to server address like ~/Images/abc.jpg Any solution please.

So i finaly had a nice part of my project done but then i had to try the application on phone which required me to configure IIS express.

Now i have a lovely message box on my screen telling me that ISS express web server won't start.

I have tried everything i could find on stackoverflow but it is still not working. (deleting IIS epxress, changing web server port, checked firewall, used netsh delete and add and more) IIS express isnt working for any of my projects and i get the message.

What could be problem, how can i solve it ?

I have written a following code like below to refresh user roles after they subscribed to my website like following:

  private void RefreshUserRoles()
            var AuthenticationManager = HttpContext.GetOwinContext().Authentication;
            var Identity = new ClaimsIdentity(User.Identity);
            Identity.AddClaim(new Claim(ClaimTypes.Role, "Subscriber"));
            AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
            (new ClaimsPrincipal(Identity), new AuthenticationProperties { IsPersistent = true});

Please note this line of code:

AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
                (new ClaimsPrincipal(Identity), new AuthenticationProperties { IsPersistent = true});

After user comes back to my website I set the cookie to be persistent, but I forgot to set the expiration for this cookie. I should set this cookie to last for 30 minutes, after which user should be asked to re-log onto the system.

Since some users never re-log on website, this leaves me with an issue, now I need to reset all users cookies in their browsers when they access the website and change their role if they cancelled the subscription. I noticed some users cancelled their subscription and never relogged but yet they still are able to use features on my website...

So my questions are:

1. How to set expiration of cookie to 30 minutes after which user will be asked to re-log onto the system.

2. How to Setup to re-check users cookies if they haven't expired in a long time so that I can reset their cookies to regular user if they cancelled subscription?

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?