|
I have a login page where I have my own label and texboxes which take input username and password, and there is a function in which there is a SP which validates username and password stored in the database.
My code in Login.aspx.cs is such that I call that function and validates username and password and redirects to next page Page2.aspx.
Now I want my site to be authorized such that if a user tries to access internal pages he couldn't be able to do that.
I have code in my WEb.config for that is
<authentication mode="Forms">
<forms cookieless="UseCookies" timeout="525600">
<authorization>
<deny users="?">
<allow users="*">
and code in login.aspx.cs is
protected void btnLogin_Click(object sender, EventArgs e)
{
validateUser = validateUser.ValidateUser(txtUserName.Text, hashedPassword);
if (Page.IsValid)
{
if (validateUser != null)
{
Response.Redirect("~/Page2.aspx");
}
else
{
lblErrorMessage.Text = "Invalid User";
}
}
}
Now when I try to run internal pages without login it automatically redirects to login page which is fine but when I put valid username and password in the login page it redirects with some "ReturnUrl" and not able to redirect to the Page2.aspx page.This is my problem.
Can anybody tell me where I am doing wrong or need to change the code somewhere?
Thanks in advance,
|
|
|
|
|
salon wrote: in the login page it redirects with some "ReturnUrl" and not able to redirect to the Page2.aspx page
Did you put your debugger in and step-through?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
Thanks for instant help....
The problem is solved...
I had made changes in Web.config and it started running
|
|
|
|
|
HI,
I am using update panel in my application.but i am facing one issue.
I have one page for new enrolment of members, and i have two user controls Step1.ascx and Step2.ascx. My functionality is that at a time olny one control is visible on the page and other will be hide. for eg when user fills all fields in step1 and press next button then step2.acsx will be be visible true and user control Step1.ascx will be visible false. all this happening at postback.
both control is under update panel to avaid post back during change of visibility.
On Step1.ascx i have one javascript variable var_pageName and its value is "Step1".
I want to update this value during post back to "Step2" when Step2 user control visible is true and vise versa. but the problem i am facing is javascript value is not updating during postback. I had tried this with scriptManager.RegisterClientScriptBlock and also with scriptManager.RegisterStartupScriptBlock by palacing it on both Usercontrol level and also on page level.
Please help as this is very urgent.
Sajid A.
|
|
|
|
|
This is the FIFTH time he has asked this question!!!!!
|
|
|
|
|
using AJAX dowsn't mean that anyone can change the architecture of web application....
even in AJAX postbacks occur ! but they are not visible to user ....
and every postback will affect the server side controls and variables only.... how come you are supposed to update value of javascript variable to be changed ?
use SESSION variables instead ...
Ashish Sehajpal
|
|
|
|
|
Is there any way to display all the virtual directories , programatically?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
using System.DirectoryServices;
DirectoryEntry _iisServer = new DirectoryEntry("IIS://localhost/W3SVC/1");
foreach (DirectoryEntry entry in _iisServer.Children)
{
Console.WriteLine(entry.Name);
foreach (DirectoryEntry rootChildern in entry.Children)
{
Console.WriteLine("\t" + rootChildern.Name);
}
}
Hope this helps
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
hi Pankaj,
you can easily do that.
public DirectoryEntries GetVirtualDirectories()
{
try
{
string serverName = "localhost";
string VirDirSchemaName = "IIsWebVirtualDir";
iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1");
DirectoryEntry folderRoot = iisServer.Children.Find("Root", VirDirSchemaName);
return folderRoot.Children;
}
For Load it into a Combo box
private void load_VirtualDir()
{
DirectoryEntries entries = GetVirtualDirectories();
foreach (DirectoryEntry d in entries)
{
cmboVirtual.Items.Add(d.Name);
}
}
Happy Coding
|
|
|
|
|
hi Abhijit,
What is iisserver here?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
private DirectoryEntry iisServer;
|
|
|
|
|
Is there any way to further explore the virtual directories(the files inside the virtual directory)?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
Every Virtual Directory should have a physical location. if you know the physical location, try to explore that one,insted of virtual directory.
Thanks
|
|
|
|
|
actually i am trying to access the virtual directory of a remote computer , where no folder is shared.
Can i explore the virual directory now?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
AFAIK, you won't be able to list virtual directories of a remote system.
|
|
|
|
|
Yes. Try using Directory Info class
Sample
DirectoryInfo info = new DirectoryInfo("IIS://localhost/W3SVC/1/ROOT/ReportServer001Test");
FileInfo[] fileinfo = info.GetFiles();
foreach (DirectoryInfo fi in fileinfo)
{
Console.WriteLine("\t" + fi.Name);
}
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
Laddie wrote: DirectoryInfo info = new DirectoryInfo("IIS://localhost/W3SVC/1/ROOT/ReportServer001Test");
Pankaj,
Insted of localhost, you can try to give the IP address of Remote system.
but , i think you should required the Credential for that
|
|
|
|
|
Laddie - This won't work as the path you specified is not correct. I guess it will be an invalid path format for the DirectoryInfo class.
Laddie wrote: foreach (DirectoryInfo fi in fileinfo)
{
Console.WriteLine("\t" + fi.Name);
}
foreach (FileInfo fi in fileinfo)
{
Console.WriteLine("\t" + fi.Name);
}
|
|
|
|
|
You are right.. It is my mistake.
I was playing with both the GetDirectories() and GetFiles() functions and which i copied to reply the code i forgot to change it in the second place.
Thanks for correcting
Thanks
Laddie
Kindly rate if the answer was helpful
|
|
|
|
|
Glad to know it helped. You are welcome
|
|
|
|
|
I am trying to get a single login working across two sub domains
(www.my.domain.com and mySubDomain.my.domain.com)
When I create the authentication cookie in www.my.domain.com, I can read most of the cookie settings, but domain does not seem to get set. I have tried setting the domain in the web.config file and also in the login code. In both cases, I can't read it (from www.my.domain). It returns an empty string.
I can't read the cookie at all from mySubDomain.my.domain.com.
Web config file Forms setting is:
<authentication mode="Forms">
<forms name="AuthCookie">
domain=".my.domain.com"
enableCrossAppRedirects="true"
loginUrl="~/Authenticate/logon.aspx"
protection="All"
timeout="60"
path="/"
/>
</forms></authentication>
Both applications have the same settings.
I also have a machineKey set (identical across both apps).
Any idea of what is wrong?
Cheers.
|
|
|
|
|
Hello everyone,
I have a query that's probably quite common, but there's a part of how Threads are managed that I don't quite fully grasp, so i'm wondering what's the best way to solve my scenario.
The functional overview is quite simple: My site visitor wants to search, he enters a query, I forward that query to a 3rd party catalog that searches for me, and I return the results to the client.
The search works over AJAX, so I'm receiving the request on an ASHX handler, and returning the HTML that the JS will then put into a div directly.
This 3rd party service is expected to take a while to respond (many seconds)
My question is how to handle the threads on the server to avoid a bottleneck.
The obviously simplest way is to have the ASHX open a WebRequest to the 3rd party catalog directly. The obvious problem is, i can only have 25 queries running simultaneously in that case (i'm picking 25 as the number of threads in my pool from now on. I know this can be changed but that's not the point.)
I want to release these threads so they can keep handling other requests while the searches I spawned are pending, so the first thing I'm doing is using an IHttpAsyncHandler
In the method where I call the 3rd party URL, i'm using HttpWebRequest.BeginGetResponse (with a callback), so that part is handled Async too.
My question is...
When I call BeginGetResponse, I can immediately free the thread that I'm in and return it to the pool.
However, when I do that, am I not spawning a new thread that is alive while the request goes on, and ends up calling my callback once it finishes?
If I AM spawing this new thread, doesn't this consume one thread from the pool too, and I'm actually getting a net effect of the same as going synchronous?
If I am NOT spawning a new thread, then how does my callback get called? Who is checking whether this async method I started is finished? (This is the main part of the puzzle that I don't quite grasp)
If a response from the 3rd party catalog takes forever, could I potentially have 1000 of these async WebRequest methods pending a response at the same time, and still be using no threads (or very few) from the 25-thread pool?
Or will I only be able to have 25 of these waiting for a response from the catalog, and the rest will be queued up by IIS?
Below I'm attaching the code that I wrote that shows what i'm doing.
This is obviously oversimplified. I left the "architectural" stuff, and removed all the things specific to my case.
Am I doing things right? Should I be using an Async HTTP Handler, AND calling BeginGetResponse?
Is there a better way?
Thank you very much for your answers!
Daniel
----------------------------------------------------------------------------------------------
<![CDATA[<%@ WebHandler Language="VB" Class="SearchHttpHandler" %>]]>
Option Strict On
Imports System.Threading
Imports System.IO
Imports System.Net
Public Class SearchHttpHandler
Implements IHttpAsyncHandler
Implements IReadOnlySessionState
'---------------------------------------------------------------------------------------
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
End Sub
'---------------------------------------------------------------------------------------
Function BeginProcessRequest(ByVal context As System.Web.HttpContext, ByVal cb As System.AsyncCallback, ByVal extraData As Object) As System.IAsyncResult Implements IHttpAsyncHandler.BeginProcessRequest
context.Response.Write("Started on thread: " & _
Threading.Thread.CurrentThread.ManagedThreadId & " - " & _
Threading.Thread.CurrentThread.IsThreadPoolThread.ToString & "<br />")
'Instantiate the AsyncResult object that'll give us a hold to the context and the callback
Dim theAsyncResult As New SearchAsyncResult(context, cb, extraData)
theAsyncResult.Search()
Return theAsyncResult
End Function
'---------------------------------------------------------------------------------------
Sub EndProcessRequest(ByVal result As System.IAsyncResult) Implements IHttpAsyncHandler.EndProcessRequest
Dim theObj As SearchAsyncResult = DirectCast(result, SearchAsyncResult)
theObj.Context.Response.Write("Ended on thread: " & _
Threading.Thread.CurrentThread.ManagedThreadId & " - " & _
Threading.Thread.CurrentThread.IsThreadPoolThread.ToString)
End Sub
'---------------------------------------------------------------------------------------
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
'======================================================================================
'======================================================================================
Public Class SearchAsyncResult
Implements IAsyncResult
Public Context As HttpContext
Private mASPNETCallback As AsyncCallback
Private mExtraData As Object
Private mIsCompleted As Boolean
Private mAsyncWaitHandle As ManualResetEvent
Private mRequest As HttpWebRequest
Private mQuery As String
'-------------------------------------------------------------
Public Sub New(ByVal context As HttpContext, ByVal ASPNETCallback As AsyncCallback, ByVal ExtraData As Object)
Me.Context = context
mASPNETCallback = ASPNETCallback
mExtraData = ExtraData
End Sub
'-------------------------------------------------------------
Public Sub Search()
If Context.Request.QueryString("q") IsNot Nothing Then
mQuery = Context.Request.QueryString("q")
End If
'Return "No Results" if there is no query
If mQuery = "" Then
Context.Response.Write("No Results")
CompleteRequest()
Exit Sub
End If
'Otherwise, make an async call
Dim URL As String = "xxxxxxx?q=" & mQuery
mRequest = DirectCast(WebRequest.Create(URL), HttpWebRequest)
mRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
mRequest.Method = "GET"
mRequest.BeginGetResponse(AddressOf SearchCallback, Nothing)
End Sub
'-------------------------------------------------------------
Private Sub SearchCallback(ByVal ar As IAsyncResult)
Dim WebResp As WebResponse = mRequest.EndGetResponse(ar)
Dim sReader As New StreamReader(WebResp.GetResponseStream())
Dim result As String = sReader.ReadToEnd()
Context.Response.Write(result)
CompleteRequest()
End Sub
'-------------------------------------------------------------
Private Sub CompleteRequest()
mIsCompleted = True
SyncLock Me
If mAsyncWaitHandle IsNot Nothing Then
mAsyncWaitHandle.Set()
End If
End SyncLock
If mASPNETCallback IsNot Nothing Then
mASPNETCallback(Me)
End If
End Sub
'---------------------------------------------------------------------
#Region "Implementation of IAsyncResult dummy members"
Public ReadOnly Property AsyncState() As Object Implements System.IAsyncResult.AsyncState
Get
Return mExtraData
End Get
End Property
Public ReadOnly Property AsyncWaitHandle() As System.Threading.WaitHandle Implements System.IAsyncResult.AsyncWaitHandle
Get
SyncLock Me
If mAsyncWaitHandle Is Nothing Then
mAsyncWaitHandle = New ManualResetEvent(False)
End If
Return mAsyncWaitHandle
End SyncLock
End Get
End Property
Public ReadOnly Property CompletedSynchronously() As Boolean Implements System.IAsyncResult.CompletedSynchronously
Get
Return False
End Get
End Property
Public ReadOnly Property IsCompleted() As Boolean Implements System.IAsyncResult.IsCompleted
Get
Return mIsCompleted
End Get
End Property
#End Region
'---------------------------------------------------------------------
End Class 'SearchAsyncResult
|
|
|
|
|
Hi,
I've built a FormView with a number of fields and a corresponding insert template. It works fine and I can insert a record with no problem. However, I now want to replace one of the text fields with a dropdownlist so I can select from a number of fixed options. I've supplied a data source which references a small list of values table:
<asp:formview id="fv1" runat="server">
DataSourceID="sdsProducts" DefaultMode="Insert">
<insertitemtemplate>
Name:
<asp:textbox id="txtName" runat="server">
Type:
<asp:dropdownlist id="ddlType" runat="server">
DataSourceID="sdlType" DataTextField="Value" DataValueField="ID" />
<asp:sqldatasource id="sdlType" runat="server">
ConnectionString="<%$ ConnectionStrings:myConnStr %>"
SelectCommand="SELECT * FROM [lovType]">
<asp:sqldatasource id="sdsProducts" runat="server">
ConnectionString="<%$ ConnectionStrings:myConnStr %>"
InsertCommand="INSERT INTO [tblProducts] ([Name], [Type])
VALUES (@Name, @Type)">
<insertparameters>
<asp:parameter name="Name" type="String">
<asp:parameter name="Type" type="String">
I can see the values in the dropdownlist but it doesn't seem to insert any value for the dropdownlist. I'm having no luck with this at all. Is it even possible to place a dropdownlist control in a FormView's InsertItemTemplate?
Thanks for looking
Evil cannot be conquered in the world... It can only be resisted within oneself.
|
|
|
|
|
Dear All,
Does anyone know how to get the number of an HTTP Response bytes sent to some client?
I`ve already done some research but nothing...
Thanks in advance.
Best regards,
Marco Alves.
|
|
|
|
|
Hello all,
In my webservice, in a webmethod named emData, I am extracting some data from a sql server database and arranging those data in a DataSet following some query. Now that DataSet is the return value of my webmethod emData. I am working with C#
How can I show that dataset in my client aspx page in a normal table after receiving it from the webservice?
Please help me to solve this out.
with regards,
Faysal
|
|
|
|