开发者

Clean URLs by turning view state off in ASP.NET C#

I have this long url, which I don't want:

 http://localhost:56563/TablesLibraryWebsite/searchresults.aspx?__VIEWSTATE=%2FwEPDwUKMTY3OTkxNDkxMWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFI2N0bDAwJGNwaFJpZ2h0UGFuZWwka2V5d29yZFNlYXJjaEdP&__EVENTVALIDATION=%2FwEWAgLoquEjAvXq39ML&type=search&keywords=Enter+keywords+%2F+publication+number&population=0&datasources=0&year=0&ctl00%24cphRightPanel%24keywordSearchGO.x=3&ctl00%24cphRightPanel%24keywordSearchGO.y=8

My form is declared like this:

<form name="search" method="get" action="searchresults.aspx" id="searchform" 
    runat="server" enableviewstate="false">
    <input type="hidden" name="type" value="search" />
    <div class="searchField">
        <input name="keywords" type="text" id="keywordSearch"
            name="keywordSearch" value="Enter keywords / publication number"
            class="watermark" />
    </div>
    <!--end searchField-->
    <div class="advanceSearchBox">
        <p><b>Narrow results by:</b></p>

        <asp:Literal ID="ltrlPopulation" runat="server" />                                
        <asp:Literal ID="ltrlDatasource" runat="server" />                                 
        <asp:Literal ID="ltrlYears" runat="server" />   

    </div>
    <!--end advanceSearchBox-->
    <div style="float: right; margin-right: 2px;">
        <asp:ImageButton ImageUrl="images/go_up.png" AlternateText="GO" Width="34" 
            Height="24" id="key开发者_StackOverflow中文版wordSearchGO" runat="server"
            EnableViewState="false" onclick="keywordSearchGO_Click" />
    </div>
</form>                 

Why am I still getting this garbage?

My web.config also has pages enableviewstate="false" too.


You are using GET as your form's method attribute. This will place the form value in URL as query strings. You should use "post" instead.


You are getting that garbage because you declared the action method on the form as GET instead of POST.


Why dont you enable viewstate? It will be stored in a hidden field else ASP.Net will do URL rewrite appending the viewstate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜