Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postback Fails On Default Document

So I've created a Web Application (not Web Site) with ASP.NET (C#) and it compiles just fine in the VS13 environment. But when I publish it on IIS, the Postback on the Default Document fails. The Default Document is called LoginPage.aspx. As soon as I click the <asp:Button> to run my code behind, all it does is refresh the page. This project has been published on my local 127.0.0.1 IP address for the time being.

I know this has been a documented issue, but I've tried many solutions and have not come across a resolution. Some solutions I have attempted:

  • Creating a brand new Web App with minimal code to attempt accessing any Postback with no success.
  • I tried the first solution presented here with no success: https://stackoverflow.com/a/7367076/4204026

I also tried URL mappings:

<urlMappings>
    <add url="~/login" mappedUrl="~/Views/LoginPage.aspx" />
    <add url="~/login/" mappedUrl="~/Views/LoginPage.aspx" />
</urlMappings>

I'm honestly at a loss as to what's happening here. One thing I did notice is when the application is being run through Visual Studio, the <form> tag on the LoginPage.aspx appears in Chrome as:

<form method="post" action="LoginPage" id="ct101" class=".myForm">

Through IIS:

<form method="post" action="./" id="ct101" class=".myForm">

Not sure if that's a problem either. I tried hard-coding the action to login to see what would happen and it does redirect to the correct page, but as suspected no Postback was fired - My Session variable returned null and no query string was used.

Here's the related LoginPage.aspx front-end code (trimmed out a bunch of unrelated HTML):

<%@ Page Title="DREW KENNEDY | WELCOME" Language="C#" MasterPageFile="Site.Master" AutoEventWireup="true" CodeBehind="LoginPage.aspx.cs" Inherits="MyMedia.Views.LoginPage" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <!-- form is located on Site.Master -->
    <asp:Button OnClick="LoginBtn_Click" CssClass="login" runat="server" name="submit" Text="Sign In" />
</asp:Content>

And the LoginBtn_Click method in LoginPage.aspx.cs:

protected void LoginBtn_Click(object sender, EventArgs e) {
    //Tried the following line while commenting out everything else to make sure Postback is being ignored
    //Response.Write("<script>alert('Test');</script>");
        try {
            AbstractPersistenceDecorator decorator = new PersistenceDecorator();
            string uname = username.Text.Trim();//username is a TextBox Control
            string pass = password.Text.Trim();//password is a TextBox control

            bool isCookieRequested = CheckBox.Checked;
            if (decorator.authenticate(uname, pass)) {//calling SQL Server for authentication
                User AuthenticatedUser = (User)Session["User"] ?? decorator.getUserInfo(uname);

                if (Session["User"] == null) Session["User"] = AuthenticatedUser;

                if (isCookieRequested) {
                    HttpCookie cookie = new HttpCookie("username", AuthenticatedUser.Username);
                    cookie.Expires.AddDays(7);
                    Response.Cookies.Add(cookie);
                } else {
                    Session.Timeout = 15;
                }
                Thread.Sleep(1600);
                //string redirect = string.Format("dashboard?username={0}", AuthenticatedUser.Username);
                Response.Redirect("dashboard?username=" + AuthenticatedUser.Username);
            }
        } catch (Exception ex) {
            //who cares?
        }
    }

Final pieces of info:

  • Running IIS 8.0
  • Application created with 4.5 Framework, Application Pool is also 4.5 Framework
  • I have ensured that ASP.NET is installed on IIS
  • I do have URL ReWriting in the global.asax file, though I'm not sure if that is related in any way (I don't see how).
  • I have no Default.aspx page

EDIT:

  • Just tested the project through 127.0.0.1 on IE11 and FF with the same result.

EDIT #2:

Additional things I have tried with no success:

  • I tried removing my URL Rewriting
  • I tried adding an empty URL Rewrite rule, i.e. ("Empty URL", "", "~/Views/LoginPage.aspx")

Additional notes:

  • I do not use Telerik
  • I do not use ISAPI
  • The project in Visual Studio was set to debug and not release
like image 883
Drew Kennedy Avatar asked Dec 05 '14 16:12

Drew Kennedy


1 Answers

I apologize for not giving enough information in the OP as I have found the answer. It turns out it had nothing to do with ASP.NET, but rather SQL Server. I stripped the code bare and after adding back one piece of code at a time and stripping away all exception handling, I found through IIS that IIS APPPOOL\.NET vX.X did not have permissions to access the database.

What I had to do is:

  • In MSQLSM, add a new Login for IIS APPPOOL\.NET v4.5

Further on, I found out that it needed the correct permissions to perform certain commands after receiving the following exception:

The SELECT permission was denied on the object 'X', database 'X', schema 'dbo'

This Was Solved Here

  • Give that new Login the proper access. Login Properties > User Mapping > checking db_datareader and public.

The code behind now executes. It still leaves the question why it was prohibiting any Postbacks, even if I removed any SQL Connectivity in the code behind. Very strange.

Anyway, thanks to those who helped.

like image 195
Drew Kennedy Avatar answered Oct 21 '22 19:10

Drew Kennedy