-
Jun 25th, 2014, 04:29 PM
#1
Thread Starter
Frenzied Member
Possible to create a web.config and new role via code
I have a system where different users can upload files. Internally to the system I have administrators and regular users who can upload files into directories protected with web.config files and appropriate roles. However I have the need on the fly when a new customer account is created to create a directory that only that customer (and internal users) can use. I "think" as part of the customer creation process I could create a directory and role based on the customerID, and then use that info to write a web.config file that grants access to the new role and secure the directory. Is this possible? Has anybody done anything like this?
Thanks!
Sean
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 25th, 2014, 05:49 PM
#2
Re: Possible to create a web.config and new role via code
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jun 25th, 2014, 06:52 PM
#3
Thread Starter
Frenzied Member
Re: Possible to create a web.config and new role via code
Originally Posted by sapator
Hmm thanks for the reply I guess I asked it before and then got sidelined. Not quite what I want to do. I guess let me try what I want to do and see if it works.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 25th, 2014, 07:26 PM
#4
Thread Starter
Frenzied Member
Re: Possible to create a web.config and new role via code
This is kind of where was going with this where intCustomerID as an index to a new row in a Customer table in SQL.
Code:
Public Function TestWriteWebConfig(ByVal intCustomerID As Int32) As Boolean
Dim strWebConfig As String = m_strSavePath & "\Customer\" & intCustomerID.ToString() & "\web.config"
Dim fs As New FileStream(HttpContext.Current.Server.MapPath(strWebConfig), FileMode.Create, FileAccess.Write)
Dim sw As New StreamWriter(fs)
Dim strRole As String = intCustomerID.ToString() & "_Customer"
Roles.CreateRole(strRole)
sw.WriteLine("<?xml version=""1.0""?>")
sw.WriteLine("<configuration>")
sw.WriteLine("")
sw.WriteLine("<system.web>")
sw.WriteLine("<authorization>")
sw.WriteLine("<allow roles=""" & strRole & """/>")
sw.WriteLine("<allow roles=""ACS""/>")
sw.WriteLine("<allow roles=""ACS_Administrators""/>")
sw.WriteLine("<deny users=""*""/>")
sw.WriteLine("</authorization>")
sw.WriteLine("</system.web>")
sw.WriteLine("")
sw.WriteLine("</configuration>")
sw.Close()
fs.Close()
Return True
End Function
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 25th, 2014, 08:05 PM
#5
Re: Possible to create a web.config and new role via code
Hi,
How about just adding an items to web.config file rather than
creating a new one? There might be some scenarios that your web.config
has other elements as well.
how-do-you-modify-the-web-config-appsettings-at-runtime
KG
-
Jun 26th, 2014, 12:18 AM
#6
Addicted Member
Re: Possible to create a web.config and new role via code
I'm not sure about modifying web.config via code, but I've experienced "File is in use" error when i tried to modify a xml file via code and result was a failure.
If you want to modify web.config with stream writer before deployment be sure you don't get "File is in use" error.
Computer Enterprise Masoud Keshavarz
For more information contact masoudk1990@yahoo.com
-
Jun 26th, 2014, 01:37 AM
#7
Re: Possible to create a web.config and new role via code
"Playing" with the root web.config, if doable, when the site is live is a very bad idea. One mistake in code and, BOOM, your website is down. Also this will require a veeeeeery long config file if you treat many users and directories, that is bad for the readability..
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jun 26th, 2014, 07:53 AM
#8
Re: Possible to create a web.config and new role via code
Not only that, but the changes may not get picked up right away. I know when I make changes to my local web.config, I have to reset the app pool before the changes get picked up.
surely there is a better way to handle this than through the web.config file.
-tg
-
Jun 26th, 2014, 09:40 AM
#9
Re: Possible to create a web.config and new role via code
surely there is a better way to handle this than through the web.config file.
Perhaps a separate XML file..
KG
-
Jun 26th, 2014, 11:57 AM
#10
Re: Possible to create a web.config and new role via code
Originally Posted by KGComputers
Perhaps a separate XML file..
KG
Except that the reason to have it in the web.config in the first place is that then IIS will control the access accordingly. Dumping it into a different file would mean self-implementation, which sounds like it would be bigger deal to over come.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|