|
I haven't done much ASP.Net so I hope this is a small problem:
I have a page where the users can log in to the website. Their role depends on what page they get redirected to, so I am handeling the LoggedIn event of the Login control:
protected void Login_LoggedIn(object sender, EventArgs e)
{
if (User.IsInRole("Admin") == true)
{
Server.Transfer("Admin/Default.aspx");
}
else if (User.IsInRole("SuperAdmin") == true)
{
Server.Transfer("SuperAdmin/Default.aspx");
}
else
{
Server.Transfer("User/Default.aspx");
}
}
I have no idea if this is the best way to do someting like this... But my problem is that when, let's say the Admin, loggs in they will get the user page(supposed to be admin's) the first time and it says that they have not been authenticated. However, if i hit back and login again it says that they have been authenticated and it goes to the right page.
Anyone have any ideas why this is hapening?
Thanks in advance
-- modified at 13:33 Sunday 23rd April, 2006
|
|
|
|
|
+ You should use the Response.Redirect method instead of the Transfer method to redirect the user to the default page.
+ Another option that you can try in the handler of the LoggedIn event handler is that after you determine the default web page based on the user role, you then simply assign the web page to the DestinationPageUrl property of the Login control, and have the control do the rest.
|
|
|
|
|
I dont think you are understanding my question. The user is not getting directed to the right page because they are not being authenticated when they hit login.
I put:
Response.Write(User.IsAuthenticated.ToString());
on the page that the user kept getting directed to after they logged in and it says false.
So for some reason, its not authenticating the user the first time they login. Which is weird because I have made it so that you need to be logged in before you can access the user page and yet it is letting them go there. So its a bit odd
Furthermore, when I switch Server.Transfer to Response.Redirect it keeps sending the user back to the login page!!?
Any ideas?
|
|
|
|
|
Sean89 wrote: I dont think you are understanding my question.
I'm sorry.
Sean89 wrote: Any ideas?
IMO, there are a couple of reasons as to why the application sends the user back to the login page:
+ The username/password is not correct (might not be this case).
+ The user account is not authorised to view the web page in the Admin or SuperAdmin folder. So could you double check the authorization settings of your application, especially for the Admin/SuperAdmin folder.
+ The authentication ticket is not added.
Have you tried to debug your application and step through your sample code line by line and see what is actually happening?
|
|
|
|
|
please check with the ispostback is true or false
with regards,
susa
|
|
|
|
|
this is the entry in db
<span id="Label1" style="font-family:Arial Narrow;font-size:XX-Large;font-weight:bold;font-style:italic;text-decoration: overline;">
Now when i retrieve in source code
string str = ds.Tables[0].Rows[1][1].ToString();
my str value contains the following value, where i found extra slashes with each quote, plus two extra quotes at the each end of the string
"<span id=\"Label1\" style=\"font-family:Arial Narrow;font-size:XX-Large;font-weight:bold;font-style:italic;text-decoration: overline;\">"
how to get rid of these quotes and slashes?
|
|
|
|
|
How do you reckon that value looks like that? Are you singe stepping through the code and looking at the watch windows?
That's the way you would write that string as a string constant, so that's how it's displayed.
---
b { font-weight: normal; }
|
|
|
|
|
>>How do you reckon that value looks like that? Are you singe stepping through the code and looking at the watch windows?
As i didn't get the desired result, so i stepped through the code looking at the watch window, and encounter these extra stuff.
>>That's the way you would write that string as a string constant, so that's how it's displayed.
sorry, i couldn't understand this.
|
|
|
|
|
sinanju wrote: >>That's the way you would write that string as a string constant, so that's how it's displayed.
sorry, i couldn't understand this.
An example:
If you have this text:
Text with "funny" characters.
and put that in a string in the code, it would be written:
string s = "Text with \"funny\" characters."
This is the way that the watch windows show it. It does so to be able to show unprintable characters like line breaks.
---
b { font-weight: normal; }
|
|
|
|
|
If a string contains quotes - which are interpretted by the compiler as start/end of string - you have to escape them to tell it that they are part of the string and not delimiting it.
Don't know about C, but in VB you can do this by by sinply doubling them - viz:
Dim str As String = ds.Tables[0].Rows[1][1].ToString.Replace(Chr(34), Chr(34) & Chr(34))
(Since Chr(34) = the quote character)
Hope that helps
Phil
|
|
|
|
|
This doesn't seem to help, im afraid.
istead the following seems to be a step to the solution
char[] strArr = ds.Tables[1].Rows[1][1].ToString().ToCharArray();
here strArr doesn't have the extra slashes or quotes, but now how to use this char array instead of string in my code.
As casting it back to string will get me the string with extra slashes as before.
|
|
|
|
|
I'm using AJAX to write Web application, there have two client (client1, client2) and server. Now i use XmlHttpRequest to send request to Server from Client1, after that, i want server send the response to Client2. But if i use Response.write(something here), Server always send to Client1, not Client2. How can i do???
Thanks!
|
|
|
|
|
You can't do that. The HTTP protocol simply doesn't work that way. You have to send a request from the client to be able to send a response back from the server.
---
b { font-weight: normal; }
|
|
|
|
|
So are there any way to do that? example some game online ?
|
|
|
|
|
Just do a request every N seconds that will ask the server if it has anything for the client. Of course you will have to write the code at the server side that will be able to do that.
But if you will only have two clients then you should defenitly write a windows application!
--------------------------------------------------------
My development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
hey
i'll know how i can catch error in asp.net DADAX
-- modified at 13:51 Sunday 23rd April, 2006
|
|
|
|
|
Please write so somebody can understand you. I didn't understood a word you said.
--------------------------------------------------------
My development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
hey and sorry
just i need to know how i can catch error in asp.net
i hope that you understand me
and thanks anyway
DADAX
|
|
|
|
|
Using "try catch" block:
try {
}
catch( Exception ex ) {
}
|
|
|
|
|
but the code is write in the file.asp
coz i create datasource and formview and the command of add is writen in ASP
so if i write try catch in the code VB or C# it's didn't worked
i hope that you understand me
DADAX
|
|
|
|
|
Hi laks here,i want some help regarding stored procedures usage,how we can use stored procedure in ASP.net,plz explain me with example
|
|
|
|
|
Stored procedures have nothing to do with ASP.NET directly.
Stored procedures are stored on a databse server, and you can call them from .NET using ADO.NET
--------------------------------------------------------
My development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
hey i'll give you an example asp.net ( VB.net ) for executing a stored procedure in sql server 2005 but it same in another database
1) the stored procedures to add record and take the paramters from textboxes
the code for stored procedures in sql is :
create PROCEDURE SP1
(
@ID bigint ,
@Name nvarchar(50),
@Description nvarchar(500),
@ProjectID bigint
)
AS
INSERT INTO [TBASE].[dbo].[TaskType]
([ID]
,[Name]
,[Description]
,[ProjectID])
VALUES
(@ID ,@Name,@Description,@ProjectID)
RETURN
2) to execute this stored procedures from asp.net
Imports System
Imports System.Data
Imports System.Data.OleDb
Dim con As New OleDbConnection("Provider=SQLNCLI.1;Data Source=DADAX\DADAX;Integrated Security=SSPI;Initial Catalog=TBase")
con.Open()
Dim MyCommand As New OleDbCommand()
MyCommand.Connection = con
Dim proc As String
proc = "EXEC SP1 " & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text
MyCommand.CommandText = proc
MyCommand.ExecuteReader()
I wish that help you
DADAX
|
|
|
|
|
dadax_85 wrote: OleDbConnection
Why are you using OleDb to connect to a SQL Server. Why not use a SqlConnection?
dadax_85 wrote: proc = "EXEC SP1 " & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "'," & TextBox4.Text
This is a security nightmare. You are advising people down the route to a SQL Injection Attack. Don't do this! See: SQL Injection Attacks and Tips on How To Prevent Them[^]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|