9

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:

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
Community
  • 1
  • 1
Drew Kennedy
  • 4,118
  • 4
  • 24
  • 34
  • How are you determining that the Post back is not happening? If you event handler throws your just swallow the exception so it might well appear to do nothing. – Ben Robinson Dec 05 '14 at 17:11
  • @BenRobinson I threw in a `Response.Write();` above the `try/catch` block while commenting out the rest of the code in the method and it still doesn't fire. It's there above in the code I presented. If an error truly happened in that situation with no error handling, I would have received an error page, which didn't happen. – Drew Kennedy Dec 05 '14 at 17:14
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 08 '14 at 20:52
  • Was Page_Load called? What was the value of Page.IsPostBack? – John Saunders Dec 08 '14 at 20:52
  • @JohnSaunders Page_Load is not being called (just did a simple print-out to a TextBox control). Where would I find the value of IsPostBack? – Drew Kennedy Dec 08 '14 at 20:57
  • 1
    It's `Page.IsPostBack`, and I suggest you set a breakpoint instead of depending on setting textbox values. – John Saunders Dec 08 '14 at 20:58
  • Oh, `Page.IsPostBack` I can test, but is there much of a point of doing these tests when I know it's being fired through Visual Studio? (I'll do it anyway). – Drew Kennedy Dec 08 '14 at 20:59
  • I set up the breakpoint in `Page_Load` and checked the value of `IsPostBack`. `Page_Load` is firing and `IsPostBack` is `true` (on submit). – Drew Kennedy Dec 08 '14 at 21:03

2 Answers2

3

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.

Community
  • 1
  • 1
Drew Kennedy
  • 4,118
  • 4
  • 24
  • 34
0

I suggest that you redirect from the default page to the Expected page then this should work. Iis default page handling is done through isapi to handle static content so the post data may not survive

Mike
  • 3,462
  • 22
  • 25